<?php

namespace app\index\Controller;

use app\admin\model\Article_CategoryModel;
use app\admin\Model\ArticleModel;
use think\Controller;
use think\db\Where;

class ArticleController extends Controller
{
    public function index(){
        extract(input());
        $where = new Where;
        if(isset($category_id) && !empty($category_id)){
            $where['category_id'] = ['like','%'.$category_id.'%'];
        }
        $data = ArticleModel::where($where)
            ->order('create_time desc')->all();
            //->paginate(3);
      //  $page = $data->render();
        // 循环的过程中修改数据集里面的数据
 //       $data->each(function ($item) {
   //         $item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
     //   });
        $category = Article_CategoryModel::all();
        //halt($category);
        return $this->fetch('index',[
            'data' => $data,
          //  'page' => $page,
            'category' => $category
        ]);
    }
    public function news(){
        $id = input('art_id');
        $data = ArticleModel::where('art_id',$id)->find();
        $result = ArticleModel::where('art_id',$id)->setInc('read_num');

        return $this->fetch('news',[
            'data' => $data
        ]);
    }
}